package com.lanou3g.springboot_demo.bean;

import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * 使用Spring Data JPA操作数据库，实体类上需要加@Entity注解、主键属性上需要加@Id注解
 */
@Table(name="message")
@Entity //@Entity注解是JPA里提供的注解，标注此类是一个实体类
@Getter
@Setter
public class Message implements Serializable {
    // 消息状态： 已读：1； 未读：2；删除：3
    /**
     *  已读状态
     */
    public static final int STATUS_READED = 1;
    /**
     *  未读状态
     */
    public static final int STATUS_UNREAD = 2;
    /**
     * 删除状态
     */
    public static final int STATUS_DELETE = 3;

    // 也是JPA里提供的注解，标注了此属性是主键ID
    @Id
    @GeneratedValue
    private Integer id;
    // 这里如果用apache的dbutils查询的话，字段名称必须和数据库中完全一样。否则结果集封装不进来
    @Column
    private Integer fromId;
    @Column
    private Integer toId;
    @Column
    private String subject;
    @Column
    private String content;
    @Column
    private Integer status;
    @Column
    private Timestamp createtime;
    @Column
    private String attachment;

    @Override
    public String toString() {
        return "Message{" +
                "id=" + id +
                ", fromId=" + fromId +
                ", toId=" + toId +
                ", subject='" + subject + '\'' +
                ", content='" + content + '\'' +
                ", status=" + status +
                ", createtime=" + createtime +
                ", attachment='" + attachment + '\'' +
                '}';
    }
}
